package com.yiwyn.demo.utils.modify.handle.router.route;

import com.yiwyn.demo.utils.modify.anno.modify.ModifyHandleClassField;
import com.yiwyn.demo.utils.modify.entity.ModifyEntity;
import com.yiwyn.demo.utils.modify.handle.event.base.BaseTypeEvent;
import com.yiwyn.demo.utils.modify.handle.handleClass.base.BaseHandle;
import com.yiwyn.demo.utils.modify.handle.router.base.BaseModifyFieldRoute;

import java.lang.reflect.Field;

public class ModifyHandleClassRoute extends BaseModifyFieldRoute {


    @Override
    public void processField(Field field, ModifyEntity.ModifyItem modifyItem, BaseTypeEvent<?> baseTypeEvent) throws InstantiationException, IllegalAccessException {
        ModifyHandleClassField modifyFieldEventAnno = field.getAnnotation(ModifyHandleClassField.class);
        String filedType = modifyFieldEventAnno.filedType();
        // in spring project, can usage applicationContext from class to get springBean
        Class<? extends BaseHandle> handleClass = modifyFieldEventAnno.handleClass();
        BaseHandle baseHandle = handleClass.newInstance();
        modifyItem.setModifyType(filedType);
        baseHandle.action(modifyItem);
    }
}
